package day14.edu;
// Created: 14/09/2025, ChangJiang Ru
public class AccountTest {
    public static void main(String[] args) {
    Account acct = new Account();

    Customer customer1 = new Customer(acct, "Tom");
    Customer customer2 = new Customer(acct, "Jerry");

    customer1.start();
    customer2.start();
    }
}

class Account{
    private double balance;

    public synchronized void deposit(double amt)
    {
        try
        {
            Thread.sleep(6000);
        }catch(InterruptedException e)
        {
            e.printStackTrace();
        }

        if(amt > 0)
            balance += amt;
        else
            return;

        System.out.println(Thread.currentThread().getName() + ": you have amt is : " + amt + ", you balance is : " + balance);
    }
}

class Customer extends Thread{
    Account account;

    public Customer(Account account)
    {
        this.account = account;
    }

    public Customer(Account account, String name)
    {
        super(name);
        this.account = account;
    }

    @Override
    public void run()
    {
        for (int i = 0; i < 3; i++) {
            try
            {
                Thread.sleep(1000);
            }catch(InterruptedException e)
            {
                e.printStackTrace();
            }

            account.deposit(1000);
        }
    }
}
